﻿using System.Linq;
using SPR.Helpers;

using TreeSharp;

namespace SPR.Classes.Warrior
{
    class Protection : RotationBase
    {        

        public override string Name
        {
            get { return "Protection Warrior"; }
        }

        public override string KeySpell
        {
            get { return "Shield Slam"; }
        }

        // adding some help
        public override string Help
        {
            get
            {
                return "----------------------------------------------------------------------\n" +
                      "This Rotation will:\n" +
                      "1. Heal using Victory Rush, Enraged Regeneration\n" +
                      "==>             Rallying Cry, Healthstone \n" +
                      "2. AutomaticCooldowns has: \n" +
                      "==> UseTrinkets \n" +
                      "==> UseRacials \n" +
                      "==> UseEngineerGloves \n" +
                      "==> Earthen Potion & Recklessness & BattleShout & Demoralizing Shout\n" +
                      "4. Best Suited for end game raiding\n" +
                      "NOTE: PvP uses single target rotation - It's not designed for PvP use. \n" +
                      "Credits to Jamjar0207\n" +
                      "----------------------------------------------------------------------\n";
            }
        }

        public override Composite SingleRotation
        {
            get
            {
                return new Sequence(
                    new PrioritySelector(
                    // Trinkets & Cooldowns
                        new Decorator(
                            ret => Units.IsTargetWorthy(Me.CurrentTarget), 
                                new PrioritySelector(
                                        Item.UseTrinkets(), 
                                        Spells.UseRacials(), 
                                        Items.UseEngineerGloves(ret => true, "Engineer's gloves"), 
                                        Buff.CastBuff("Lifeblood", ret => true, "Lifeblood"), 
                                        Items.UseBagItem("Earthen Potion",      ret => Me.HealthPercent < 35, "Earthen Potion"), 
                                        Spells.CastSelfSpell("Recklessness",    ret => (Me.CurrentTarget.HealthPercent < 20 || Buffs.UnitHasHasteBuff(Me)) && Me.HealthPercent > 80, "Recklessness"))), 
                                        Spells.CastSpell("BattleShout",         ret => Me.RagePercent < 80, "Battle Shout for Rage"), 
                                        Buff.CastDebuff("Demoralizing Shout",   ret => !Buff.TargetHasDebuff("Demoralizing Shout"), "Demoralizing Shout"), 
                    // Extra Action button automation
                    Items.RunMacroText("/click ExtraActionButton1", ret => (Units.IsFadingLight() || Units.IsShrapnel() || Units.IsHourofTwilight()) && SPR.Instance.AutoExtraActionButton, "[Push Button] ExtraActionButton1"),
                    // Interupts
                    Spells.CastInterupt("Pummel",               ret => true, "Pummel"), 
                    Spells.CastInterupt("Shockwave",            ret => true, "Shockwave"), 
                    Spells.CastSelfSpell("Spell Reflection",    ret => Me.CurrentTarget.IsCasting, "Spell Reflection"),                    
                    Spells.CastInterupt("Concussion Blow",      ret => true, "Concussion Blow"), 
                    // Spells.CastInterupt("Heroic Throw",       ret => true, "Heroic Throw"), //if you are gag order talented
                    // START AoE
                    new Decorator(
                        ret => Units.CountEnnemiesInRange(Me.Location, 12) >= 3, 
                        new PrioritySelector(
                            // Spells.CastAreaSpell("Intimidating Shout", 8, false, 3, 0.0, 0.0, ret => true, "Intimidating Shout"), //only use if glyphed
                            Spells.CastSelfSpell("Retalliation", ret => Unit.EnemyUnits.Count() >= 3, "Retalliation"), 
                            Spells.CastAreaSpell("Cleave", 10, true, 3, 0.0, 0.0, ret => Me.RagePercent > 50 && Unit.EnemyUnits.Count() >= 3, "Cleave"), 
                            Spells.CastSelfSpell("Inner Rage", ret => Me.RagePercent >= 85 && !Buff.PlayerHasBuff("Berserker Rage") && Unit.EnemyUnits.Count() >= 3, "Inner Rage"), 
                            Spells.CastConicSpell("Shockwave", 11f, 33f, ret => Unit.EnemyUnits.Count() >= 3, "Shockwave"),
                            Buff.CastDebuff("Rend",             ret => Unit.EnemyUnits.Count() >= 3 && !Buff.TargetHasDebuff("Rend"), "Rend"), 
                            Spells.CastAreaSpell("Thunder Clap", 10, false, 3, 0.0, 0.0, ret => Unit.EnemyUnits.Count() >= 3, "Thunder Clap"), 
                            Spells.CastSpell("Revenge",         ret => Unit.EnemyUnits.Count() >= 3, "Revenge"))),
                    // START Main Rotation
                    Spells.CastSpell("Heroic Strike",           ret => Me.RagePercent > 50, "Heroic Strike Rage Dump"), 
                    Spells.CastSelfSpell("Inner Rage",          ret => Me.RagePercent >= 85 && !Buff.PlayerHasBuff("Berserker Rage"), "Inner Rage"), 
                    Spells.CastSelfSpell("Berserker Rage",      ret => !Buff.PlayerHasBuff("Inner Rage"), "Berserker Rage"), 
                    Spells.CastSelfSpell("Shield Block",        ret => true, "Shield Block"), 
                    Spells.CastSpell("Shield Slam",             ret => true, "Shield Slam"), 
                    Spells.CastAreaSpell("Thunder Clap", 10, false, 1, 0.0, 0.0, ret => Buff.TargetDebuffTimeLeft("Rend").TotalSeconds <= 3, "ThunderClap"), 
                    Buff.CastDebuff("Rend",                     ret => !Buff.TargetHasDebuff("Rend"), "Rend"), 
                    Spells.CastSpell("Devastate",               ret => Spells.SpellCooldown("Shield Slam").TotalSeconds > 1.5, "Devastate waiting for Shield Slam"), 
                    Spells.CastConicSpell("Shockwave", 11f, 33f, ret => true, "Shockwave"), 
                    Spells.CastSpell("Concussion Blow",         ret => true, "Concussion Blow"), 
                    Spells.CastSpell("Revenge",                 ret => true, "Revenge"), 
                    Spells.CastSpell("Devastate",               ret => true, "Devastate"), 
                    Buff.CastBuff("Battle Shout",               ret => true, "Battle Shout")));
            }
        }

        public override Composite Medic
        {
            get
            {
                return new Decorator(
                    ret => Me.HealthPercent < 100, 
                    new PrioritySelector(
                        Spells.CastSpell("Victory Rush",                ret => Me.HealthPercent < 50 || Buff.PlayerBuffTimeLeft("Victory Rush").TotalSeconds < 1.5, "Victory Rush"),
                        Spells.CastSelfSpell("Shield Wall",             ret => Me.HealthPercent < 35 && !Buff.PlayerHasBuff("Rallying Cry") && !Buff.PlayerHasBuff("Enraged Regeneration"), "Shield Wall"),
                        Spells.CastSelfSpell("Enraged Regeneration",    ret => Me.HealthPercent < 35 && !Buff.PlayerHasBuff("Rallying Cry") && !Buff.PlayerHasBuff("Shield Wall"), "Enraged Regeneration"),
                        Spells.CastSelfSpell("Rallying Cry",            ret => Me.HealthPercent < 35 && !Buff.PlayerHasBuff("Shield Wall") && !Buff.PlayerHasBuff("Enraged Regeneration"), "Rallying Cry"),
                        Items.UseBagItem("Healthstone",                 ret => Me.HealthPercent < 35 && !Buff.PlayerHasBuff("Rallying Cry") && !Buff.PlayerHasBuff("Enraged Regeneration") && !Buff.PlayerHasBuff("Shield Wall"), "Healthstone")));                                                            
            }
        }

        public override Composite PreCombat
        {
            get
            {
                return new PrioritySelector(
                        new Decorator(
                            ret => !Me.Mounted && !Me.Dead && !Me.Combat && !Me.IsFlying && !Me.IsOnTransport && !Me.HasAura("Food") && !Me.HasAura("Drink"),
                            new PrioritySelector(
                                Buff.CastBuff("Battle Shout",           ret => !Buff.PlayerHasBuff("Battle Shout"), "Battle Shout"))));
            }
        }

        public override Composite PVPRotation
        {
            get { return SingleRotation; }
        }

        public override Composite PVERotation
        {
            get { return SingleRotation; }
        }
    }
}